//
//  AppInfo.m
//  应用管理
//
//  Created by 张建国 on 16/1/18.
//  Copyright © 2016年 张建国. All rights reserved.
//

#import "AppInfo.h"

@implementation AppInfo
- (instancetype) initWithDic:(NSDictionary *)dic{
    if (self = [super init]) {
        self.name = dic[@"name"];
        self.icon = dic[@"icon"];
    }
    return self;
}

+ (instancetype) appInfoWithDic:(NSDictionary *)dic{
    return [[self alloc] initWithDic:dic];
}

+(NSArray *)appInfoList{
    //1.1 bundle
    NSBundle *bundle = [NSBundle mainBundle];
    //1.2 获取plist的路径
    NSString *path = [bundle pathForResource:@"app" ofType:@"plist"];
    //1.3 加载plist
    //        _appInfos = [NSArray arrayWithContentsOfFile:path];
    NSArray *dicArray = [NSArray arrayWithContentsOfFile:path];
    
    NSMutableArray *temArray = [NSMutableArray array];
    // 1.4 字典转模型
    for (NSDictionary *dic in dicArray) {
        // 调用appInfo的类方法
        AppInfo *appInfo = [AppInfo appInfoWithDic:dic];
        
        [temArray addObject:appInfo];
        
    }
    return temArray;

}

@end
